package com.example.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.domain.fanweiKQ.DkDateEntity;
import com.example.domain.fanweiKQ.HolidayEntity;
import com.example.domain.fanweiKQ.JbtsEntity;
import com.example.domain.fanweiKQ.JiaBanEntity;
import com.example.service.KqbbService;

import lombok.extern.slf4j.Slf4j;

/**
 * 考勤报表
 * 
 * @author ljl
 *
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class KqbbController {

	@Autowired
	private KqbbService kqbbService;

	/**
	 * 获取泛微系统的打卡记录
	 * 
	 * @return
	 */
	@RequestMapping("/DkDate")
	public List<DkDateEntity> getDkDate(@RequestParam String day, @RequestParam String key) {
		return kqbbService.queryDk(day, key);
	}

	/**
	 * 交补天数
	 * 
	 * @param day
	 * @return
	 */
	@RequestMapping("/jbts")
	public List<JbtsEntity> getJbts(@RequestParam String day, @RequestParam String key) {
		List<JbtsEntity> list = kqbbService.queryJbts(day, key);
		return list;
	}
//	@RequestMapping("/jbts")
//	public Map<String, Object> getJbts(@RequestParam String day, @RequestParam(defaultValue = "1") Integer pageNum,
//			@RequestParam(defaultValue = "10") Integer pageSize) {
//		List<JbtsEntity> list = kqbbService.queryJbts(day);
//		List<JbtsEntity> subList = list.stream().skip((pageNum - 1) * pageSize).limit(pageSize)
//				.collect(Collectors.toList());
//		// 存返给前端的数据
//		JSONObject jsonObject = new JSONObject();
//		jsonObject.put("pageNum", pageNum);
//		jsonObject.put("pageSize", pageSize);
//		jsonObject.put("totalNum", list.size());
//		jsonObject.put("subList", subList);
//		return jsonObject;
//	}

	/**
	 * 考勤详情 加班：平时加班时长、周末加班时长、法定加班时长 请假：事假时长、病假时长、产假时长
	 * 迟到早退：迟到次数、严重迟到次数、早退次数、严重早退次数、旷工次数 其它：应出勤天数 其它：应出勤天数、未勤时长（当月入离职）
	 * 
	 * @param date
	 * @return
	 */
	@RequestMapping("/kqDetail")
	public List<JiaBanEntity> getkqDetail(@RequestParam String date) {
		return kqbbService.queryKq(date);
	}

	/**
	 * 获取节假日
	 * 
	 * @param day
	 * @return
	 */
	@RequestMapping("/holiday")
	public List<HolidayEntity> getHoliday(@RequestParam String day) {
		return kqbbService.queryHoliday(day);
	}

	/**
	 * 交补天数导出
	 * 
	 * @param day
	 * @return
	 */
	@RequestMapping("/jbts/export")
	public String jbtsExport(@RequestParam String day, @RequestParam String key) {
		return "/excel/" + kqbbService.jbtsExport(day, key);
	}

}
